package com.qf.news.controller;

import com.qf.news.domain.User;
import com.qf.news.response.Response;
import com.qf.news.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@RestController
@RequestMapping("/login")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @PostMapping("/UserLogin")
    public Response<User> login(@RequestBody User user) {
        User login = userService.userlogin(user.getUsername(), user.getPassword());
        if (Objects.nonNull(login)) {
            System.out.println("成功");
            return Response.success(login);

        } else {
            System.out.println("失败");
            return Response.fail(null);
        }
    }
}

